/*
* Copyright 2010 Pavel Kozhin 
*
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
* http://www.apache.org/licenses/LICENSE-2.0
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed  under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License.
*
* Author: Pavel Kozhin.
*/

package org.etherframework.behaviour.rules.controls
{
	import org.etherframework.behaviour.rules.context.IContext;
	import org.etherframework.behaviour.rules.core.Control;
	
	public class Break extends Control implements IInteractive
	{
		public function Break()
		{
			super();
		}
		
		override public function set context(value:IContext):void
		{
			if (!value)
				return;
			
			super.context = value;
			
			if (_condition)
			{
				if (global)
					descriptor.owner.context.close();
				else
					descriptor.parent.context.close();
			}
			else
			{
				context.close();
			}
		}
		
		private var _condition:Boolean = true;
		
		[Bindable]
		[Inspectable(defaultValue="true")]
		public function get condition():Boolean
		{
			return _condition;
		}
		
		public function set condition(value:Boolean):void
		{
			_condition = value;
		}
		
		private var _global:Boolean = false;
		
		[Bindable]
		[Inspectable(defaultValue="false")]
		public function get global():Boolean
		{
			return _global;
		}

		public function set global(value:Boolean):void
		{
			_global = value;
		}

	}
}